<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维码登录</title>
</head>
<body>
<div class="qrCodeImg-box" id="qrImgDiv"></div>

</body>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

<button class="btn" >授权登录</button>
<script>
    let uuid = null
    $(document).ready(function(){
        initQrImg();

        $(".btn").click(()=>{
            console.log(uuid);
            console.log("click")
           $.get("/app/bindUserIdAndToken?id="+uuid);
        })
    });



    function initQrImg(){
        $("#qrImgDiv").empty();
        var xmlhttp;
        xmlhttp=new XMLHttpRequest();
        xmlhttp.open("GET",getQrPath,true);
        xmlhttp.responseType = "blob";
        xmlhttp.onload = function(){
            console.log(this);
            uuid = this.getResponseHeader("uuid");
            console.log(uuid)

            if (this.status == 200) {
                var blob = this.response;
                console.log(blob)
                var img = document.createElement("img");
                img.className = 'qrCodeBox-img';
                img.onload = function(e) {
                    window.URL.revokeObjectURL(img.src);
                };
                img.src = window.URL.createObjectURL(blob);
                document.getElementById("qrImgDiv").appendChild(img);
                console.log(img)
                initWebSocket();
            }
        }
        xmlhttp.send();
    }



    var path = "://localhost:8080";
    var getQrPath =  "http" + path + "/app/getLoginQr";
    var wsPath =     "ws" + path + "/websocket/";




</script>
</html>